package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.ArrayList;

import bean.MyCarBean;
import zhang.automobileservice.R;

/**
 * Created by Administrator on 2016/8/10.
 */
public class MyCarAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<MyCarBean> arrayList;

    public MyCarAdapter(Context context, ArrayList<MyCarBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_mycar_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        viewHolder.tv_carbrand.setText(arrayList.get(position).getCarBrand());
        viewHolder.tv_carname.setText(arrayList.get(position).getCarName());
        viewHolder.tv_state.setText(arrayList.get(position).getStatu());
        viewHolder.num.setText(arrayList.get(position).getDefaultNo());
        viewHolder.money_num.setText(arrayList.get(position).getTicketNum());
        viewHolder.score_num.setText(arrayList.get(position).getScoreNum());
        return convertView;
    }

    public static class ViewHolder {
        public View rootView;
        public TextView tv_carbrand;
        public TextView tv_carname;
        public ImageButton ib_nextdetail;
        public TextView tv_state;
        public TextView default_num;
        public TextView num;
        public TextView noney;
        public TextView money_num;
        public TextView score;
        public TextView score_num;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.tv_carbrand = (TextView) rootView.findViewById(R.id.tv_carbrand);
            this.tv_carname = (TextView) rootView.findViewById(R.id.tv_carname);
            this.ib_nextdetail = (ImageButton) rootView.findViewById(R.id.ib_nextdetail);
            this.tv_state = (TextView) rootView.findViewById(R.id.tv_state);
            this.default_num = (TextView) rootView.findViewById(R.id.default_num);
            this.num = (TextView) rootView.findViewById(R.id.num);
            this.noney = (TextView) rootView.findViewById(R.id.noney);
            this.money_num = (TextView) rootView.findViewById(R.id.money_num);
            this.score = (TextView) rootView.findViewById(R.id.score);
            this.score_num = (TextView) rootView.findViewById(R.id.score_num);
        }

    }
}
